package MyTimer;

public class MyTask implements Comparable<MyTask>{
    //创建任务与执行时间
    private Runnable runnable;
    private long time;

    public MyTask(Runnable runnable, long time) {
        if(runnable == null) {
            throw new IllegalArgumentException("任务不能为空");
        }
        if(time == 0) {
            throw new IllegalArgumentException("时间不能为零");
        }
        this.runnable = runnable;
        //计算出任务执行的具体时间
        this.time = time + System.currentTimeMillis();
    }

    public Runnable getRunnable() {
        return runnable;
    }

    public long getTime() {
        return time;
    }

    @Override
    public int compareTo(MyTask o) {
        if(this.getTime() > o.getTime()) {
            return 1;
        } if(this.getTime() < o.getTime()) {
            return -1;
        } else {
            return 0;
        }

    }
}
